package com.etlmaster.executor.steps.file;

import com.etlmaster.executor.Step;
import com.etlmaster.executor.StepMeta;
import com.etlmaster.executor.annotation.StepInstruction;
import com.etlmaster.executor.processors.File.FileHelper;
import com.etlmaster.executor.utils.StepState;

/**
 * 
 * @author MeiKefu
 * @date 2015-2-16
 */
@StepInstruction("fileMove")
public class FileMoveStep extends Step {

	private FileMoveStepMeta meta;

	public FileMoveStep(StepMeta meta) {
		super(meta);
		this.meta = (FileMoveStepMeta) meta;
	}

	@Override
	protected int handle() {
		String fileUri = meta.getFileURI();
		String newFileUri = meta.getNewFileURI();
		if(FileHelper.moveAndCheckResult(fileUri, newFileUri))
		{
			meta.log("INFO", "移动文件{}到{}成功", fileUri, newFileUri);
			return StepState.RUNNING_SUCCESSED;
		}else{
			return StepState.RUNNING_FAILED;
		}
	}

	@Override
	public boolean stop() {
		return false;
	}
}
